package com.yyd.designmodel.responsibilitychain;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @Description：[ 过滤器链，将责任链当成过滤器链 ]
 *
 * @ProjectName：[designmodel]
 * @PackageName：[com.yyd.designmodel.responsibilitychain.FilterChain]
 * @CreateDate：[2015-2-2  上午10:01:31] 
 * @Author：[yuyidi]
 */
public class FilterChain implements Filter {
    private List<Filter> filters = new ArrayList<Filter>();
    int index = 0;//标示当前访问的是哪一个过滤器
    
    public FilterChain addFilter(Filter f){
        this.filters.add(f);
        return this;
    }
    
    public void doFilter(Request request, Response response, FilterChain chain) {
        if(index == filters.size()){
            return;
        }
        Filter f = filters.get(index);
        index++;
        f.doFilter(request, response, chain);
    }

}
